//
//  ZYAdapterImp.m
//  DesignMode
//
//  Created by wangzhipan on 2024/10/29.
//

#import "ZYAdapterImp.h"

@implementation ZYOldClass
- (int)barData
{
    return 10;
}
- (void)foo:(int)data
{
    NSLog(@"doing data: %d", data);
}
@end



@interface ZYNewTarget()
@property (nonatomic, strong) id<IOldAdaptee>adaptee;
@end

@implementation ZYNewTarget
- (instancetype)initWithOldAdaptee:(id<IOldAdaptee>)adaptee
{
    if (self = [super init]) {
        self.adaptee = adaptee;
    }
    return self;
}

- (void)process
{
    //先进行其他适配
    int data = [self.adaptee barData];
    [self.adaptee foo:data];
    //再继续进行其他适配处理
}
@end


@implementation ZYAdapterMainPage

- (void)setup
{
    id<IOldAdaptee> adaptee = [[ZYOldClass alloc] init];
    
    id<INewTarget> target = [[ZYNewTarget alloc] initWithOldAdaptee:adaptee];
    [target process];
}
@end
